package cn.com.captureNetPacket.util;

import java.util.EnumSet;

import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;

public class JsonPathUtil {
	public static final Configuration DEFAULT_CONFIG = Configuration.builder()
			.mappingProvider(new JacksonMappingProvider())
			.jsonProvider(new JacksonJsonNodeJsonProvider())
			.options(EnumSet.noneOf(Option.class)).build();

	public static <T> String getValue(String msg, String expression) {
		return getValue(msg, expression, String.class);
	}

	public static <T> T getValue(String msg, String expression, Class<T> clazz) {
		return JsonPath.using(DEFAULT_CONFIG).parse(msg).read(expression, clazz);
	}
}
